package com.leiduoduo.oms.service;

import com.leiduoduo.oms.dao.OrderDao;
import com.leiduoduo.oms.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderDao orderDao;

    @Override
    public boolean addOrder(Order order) {
        order.setCreated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
                .setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        System.out.println(order.toString());
        return orderDao.addOrder(order);
    }

    @Override
    public boolean delOrder(Order order) {
        order.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return orderDao.delOrder(order);
    }

    @Override
    public boolean upOrder(Order order) {
        order.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return orderDao.upOrder(order);
    }
    @Override
    public boolean upOrderState(Order order) {
        order.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return orderDao.upOrderState(order);
    }

    @Override
    public Order getOrderById(int id) {
        return orderDao.getOrderById(id);
    }

    @Override
    public List<Order> getOrderList() {
        return orderDao.getOrderList();
    }

    @Override
    public List<Order> getOrderListByPage(Map<String, Object> map) {
        return orderDao.getOrderListByPage(map);
    }

    @Override
    public int getOrderListCount() {
        return orderDao.getOrderListCount();
    }
}
